package com.zengqingfa.dubbo.mall.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan;
import com.zengqingfa.dubbo.mall.service.OrderService;
import com.zengqingfa.dubbo.mall.service.OrderServiceImpl;
import com.zengqingfa.dubbo.mall.service.OrderServiceXml;
import com.zengqingfa.dubbo.mall.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @fileName: OrderConsumerConfig
 * @author: zengqf3
 * @date: 2021-4-12 16:26
 * @description:
 */
// @Configuration
//扫描dubbo注解
// @DubboComponentScan(basePackages = {"com.zengqingfa.dubbo.mall.service"})
public class OrderConsumerConfig {

    // <dubbo:application name="mall-order"></dubbo:application>
    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("mall-order");
        return applicationConfig;
    }

    // <dubbo:registry address="zookeeper://localhost:2181"></dubbo:registry>
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://localhost:2181");
        return registryConfig;
    }

    /**
     * <dubbo:reference id="userService" interface="com.zengqingfa.dubbo.com.zengqingfa.dubbo.mall.service.UserService"></dubbo:reference>
     * @return
     */
    @Bean
    public ReferenceConfig<UserService> userServiceConfig() {
        ReferenceConfig<UserService> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setApplication(applicationConfig());
        referenceConfig.setRegistry(registryConfig());
        referenceConfig.setInterface(UserService.class);
        return referenceConfig;
    }

    @Bean
    public UserService userService() {
        return userServiceConfig().get();
    }

    @Bean
    public OrderService orderService() {
        return new OrderServiceImpl();
    }
}
